﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MainProGrid
{
    public partial class EventEditorFrm : Form
    {
        public EventEditorFrm(CustomEvent CurrentEvent)
        {
            InitializeComponent();
            this.CurrentEvent = CurrentEvent;
        }

        public CustomEvent CurrentEvent 
        { 
            get;
            set;
        }

        private void EventEditor_Load(object sender, EventArgs e)
        {
            string text = "function "+CurrentEvent.Name+"("+string.Join(",",CurrentEvent.Args.Keys.ToArray())+"){";
            lblTop.Text = text;
            if (CurrentEvent.Value != null)
            {
                string val = CurrentEvent.Value.ToString();
                if (!string.IsNullOrEmpty(val))
                {
                    MainScriptEditor.Script = val;
                }
            }
            StringBuilder sb=new StringBuilder();
            sb.Append(CurrentEvent.Description);
            foreach (var item in CurrentEvent.Args)
            {
                sb.Append(Environment.NewLine + item.Key + ":" + item.Value);
            }
            TxtDescription.Text = sb.ToString();
        }
        public string Value { get; set; }
        private void EventEditor_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Value = MainScriptEditor.Script;
        }
    }
}
